<template>
  <view>
    <!-- 宫格组件 -->
	<view v-if="list && list.length > 0">
		<view class="mobile-item-container" v-for="(item, index) in list" :key="index">
			<template v-if="item.path=='/'">
				<view v-for="(child, childIndex) in item.children" :key="childIndex">
					<view style="font-size: 40rpx; font-weight: bold; padding: 0 0 40rpx 0;">
						{{child?child.meta.title:"" }} 
					</view> 
					  <u-grid col="3">
						<u-grid-item  @click="navigateToUrl(child)">
						  <u-icon name="star" color="#2979ff" size="60rpx"></u-icon>
						  <text class="btn-text">{{child?child.meta.title:"" }} </text>
						</u-grid-item>
					  </u-grid>
				</view>
				<br>
				<Gap/>
			</template>
			<template v-else>
				<view style="font-size: 40rpx; font-weight: bold; padding: 0 0 40rpx 0;">{{item.meta?item.meta.title:"" }}</view>
				  <u-grid col="3">
					<u-grid-item v-for="(child, childIndex) in item.children" :key="childIndex" @click="navigateToUrl(child)">
					  <u-icon name="star" color="#2979ff" size="60rpx"></u-icon>
					  <text class="btn-text">{{child.meta.title}}</text>
					</u-grid-item>
				  </u-grid>
				  <br>
				  <Gap />
			</template>
		</view>
	</view> 
  </view>
</template>

<script>
  import { getRouters } from '@/api/menu'
  import Navbar from '@/components/navbar/Navbar'
  import Gap from '@/components/gap/Gap'
  export default {
	  components: {  
		  Gap,
    Navbar,
	  },
    data() {
      return {
        current: 0,
        swiperDotIndex: 0,
        data: [{
            image: '/static/images/banner/banner01.jpg'
          },
          {
            image: '/static/images/banner/banner02.jpg'
          },
          {
            image: '/static/images/banner/banner03.jpg'
          }
        ],
		list:[]
      }
    },
	onLoad () {
	 this.loadData();
	},
    methods: {
		// 加载菜单数据
		loadData () {
			getRouters().then(res => {
			  this.list = res.data;
			})
		},
      clickBannerItem(item) {
        console.info(item)
      },
      changeSwiper(e) {
        this.current = e.detail.current
      },
      changeGrid(e) {
        this.$modal.showToast('模块建设中~')
      },
	  handleToUser() {
	    this.$tab.navigateTo('/pages/user/index')
	  },
	  navigateToUrl (obj) {
		  console.log(111)
	  	const url = "/pages/"+obj.component
		console.log(url)
	    uni.navigateTo({ url: url })
	  }
    }
  }
</script>

<style lang="scss">
  /* #ifndef APP-NVUE */
  page {
    display: flex;
    flex-direction: column;
    box-sizing: border-box;
    background-color: #fff;
    min-height: 100%;
    height: auto;
  }

  view {
    font-size: 14px;
    line-height: inherit;
  }

  /* #endif */

  .text {
    text-align: center;
    font-size: 26rpx;
    margin-top: 10rpx;
  }

  .grid-item-box {
    flex: 1;
    /* #ifndef APP-NVUE */
    display: flex;
    /* #endif */
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 15px 0;
  }

  .uni-margin-wrap {
    width: 690rpx;
    width: 100%;
    ;
  }

  .swiper {
    height: 300rpx;
  }

  .swiper-box {
    height: 150px;
  }

  .swiper-item {
    /* #ifndef APP-NVUE */
    display: flex;
    /* #endif */
    flex-direction: column;
    justify-content: center;
    align-items: center;
    color: #fff;
    height: 300rpx;
    line-height: 300rpx;
  }

  @media screen and (min-width: 500px) {
    .uni-swiper-dot-box {
      width: 400px;
      /* #ifndef APP-NVUE */
      margin: 0 auto;
      /* #endif */
      margin-top: 8px;
    }

    .image {
      width: 100%;
    }
  }
</style>
